let express=require('express');
let router=express.Router();
let mongoose=require('mongoose');

//获取试卷id
router.post('/query',async function(req,resp){
    //当前试卷id
    let {testId}=req.body;
    //获取
    let re=await mongoose.model('testsModel').find({
        _id:testId
    }).populate({
        path:'exerciseId',
        populate:{
            path:'pointId'
        }
    });

    if(re){
        resp.send({
            code:1,
            message:'获取成功',
            data:re
        })
    }else{
        resp.send({
            code:2,
            message:'获取失败'
        })
    }
})




//添加到tested
router.post('/add',async function(req,resp){
    let {studentId,testId,typeId,answers,score,accuracy,durations}=req.body;
    
    //studentId:考生id   testId：试卷id  typeId：试卷类型id  answers：考生答案  score：分数 accuracy：正确率   durations：考生所用时长
    //计算分数、正确率、时长
    let re=await mongoose.model('testedsModel').create({
        studentId: studentId,
        testId: testId,
        typeId: typeId,
        answers: answers,
        score: score,
        accuracy:accuracy,
        durations:durations
    })

    if(re){
        resp.send({
            code:1,
            message:'增加成功',
            data:re
        })
    }else{
        resp.send({
            code:2,
            message:'增加失败'
        })
    }
})




module.exports=router;